const osd = require('./osd');
const path = require('path');
const klaw = require('klaw');
// const arguments = process.argv.splice(2);

// 阿里云
let osdConfig = {
  accessKeyId: 'LTAI5tHSDf1rq5xdCjFX1ViK',
  accessKeySecret: 'qjLfbuFuP2fqFbHcPneBeeasFyhEQs',
  // bucketName: 'ruizhizone',
  bucketName: 'ruizhizone-test',
  endPoint: 'oss-cn-nanjing.aliyuncs.com',
  region: 'oss-cn-nanjing',
  path: '',
  timeout: 30000,
  type: 1,
};
// let osdConfig = {
//   "accessKeyId": arguments[0],
//   "accessKeySecret": arguments[1],
//   "bucketName": arguments[2],
//   "endPoint": arguments[3],
//   "region": arguments[4],
//   "path": arguments[5],
//   "timeout": parseInt(arguments[6]),
//   "type": parseInt(arguments[7])
// };
// let osdConfig = {
//   accessKeyId: 'LTAI5tHSDf1rq5xdCjFX1ViK',
//   accessKeySecret: 'qjLfbuFuP2fqFbHcPneBeeasFyhEQs',
//   bucketName: arguments[0],
//   endPoint: 'oss-cn-hangzhou.aliyuncs.com',
//   region: 'oss-cn-hangzhou',
//   path: '',
//   timeout: 30000,
//   type: 1,
// };

// 华为云
// let osdConfig = {
//   "accessKeyId": "SGPKCMX0ZTGWPQHFE3IR",
//   "accessKeySecret": "MpqzyMpLyeJLT4iuWy6lu6kc5kiVGSYeDMbrjVpm",
//   "bucketName": "sbc",
//   "endPoint": "obs.cn-east-2.myhuaweicloud.com",
//   "region": "cn-east-2",
//   "path": "mini",
//   "timeout": 30000,
//   "type": 3
// }

// 腾讯云
// let osdConfig = {
//   "accessKeyId": "AKID2CBuSmShT3VklZ4TbeQwEH4e2DLDnuQj",
//     "accessKeySecret": "DF7Tr5bDerrc8OyLcvylUxBBxZw3whV3",
//     "bucketName": "kyw-1257829190",
//     "endPoint": "cos.ap-beijing.myqcloud.com",
//     "region": "ap-beijing",
//     "path": "mini",
//     "timeout": 30000,
//     "type": 2
// }

const osdClient = osd.getOsdClient(osdConfig);
const basePath = path.join(__dirname, '..');
const items = [];
const dir = path.join(basePath, '/src/assets/image/');
klaw(dir)
  .on('data', (item) => {
    if (item.stats.isFile()) {
      items.push(item.path);
    }
  })
  .on('end', async () => {
    items.forEach((item) => {
      const ossKey = item.replace(dir, '').replace(/\\/g, '/');
      const prefix = osdConfig.path;
      osdClient.putObjectAbsolute(item, `${prefix}/assets/image/${ossKey}`);
    });
  });
module.exports = osdConfig;
